<?php
/**
 * IG_Web_Element_Table_Row
 *
 * @author maomao.thx@gmail.com
 * @copyright Copyright (c) 2009 Green Shore (http://www.iwgame.com)
 * @version $Id: Row.php 524 2011-05-24 01:44:20Z mmxie $
 */
require_once 'IG/Web/Element.php';
class IG_Web_Element_Table_Row extends IG_Web_Element
{
    protected $_cells;

    /**
     * @return array
     */
    public function getCells()
    {
        return $this->_cells;
    }

    /**
     *
     * @param cells
     * @return IG_Web_Element_Table_Row
     */
    public function setCells($cells)
    {
        $this->_cells = $cells;
        return $this;
    }

    /**
     *
     * @param IG_Web_Element_Table_Cell $cell
     * @return IG_Web_Element_Table_Row
     */
    public function addCell($cell)
    {
        $this->_cells[] = $cell;
        return $this;
    }

    /**
     *
     * @param string $content
     * @return string
     */
    function render($content)
    {
        $attribs = $this->getAttribs();
        if ($this->getName() != null) {
            $attribs['name'] = $this->getName();
        }

        if ($this->getId() != null) {
            $attribs['id'] = $this->getId();
        }

        if (isset($attribs['enable']) && $attribs['enable'] == false) {
            return $content;
        }

        // build the element
        $xhtml = '<tr'
                . $this->_htmlAttribs($attribs)
                . '>' . PHP_EOL;
        if (empty($this->_cells)) {
            return $xhtml . '</tr>';
        }
        foreach ($this->_cells as $cell) {
            $xhtml = $cell->render($xhtml) . PHP_EOL;
        }

        return $content . $xhtml . '</tr>';
    }
}